document.ready(function() {
    var width = document.body.offsetWidth;
    var height = document.documentElement.clientHeight;
    var msgLeft = (width - 500) / 2;
    var msgTop = (height - 228) / 2;
    var obj = getItem('logBar');
    
    obj.style.position = 'absolute';
    obj.style.left = msgLeft + 'px';
    obj.style.top = msgTop + 'px';
    obj.style.display = '';
});

function enterPress(e) {
    var e = e || window.event;
    if (e.keyCode == 13) {
        login();
    }
}

function login() {
    if (isEmpty('username') || isWicked('username')) {
        showTip('用户名格式错误');
        return;
    }
    if (isEmpty('password') || isWicked('password')) {
        showTip('密码格式错误');
        return;
    }

    var param = {};
    param.ctrl = 'account';
    param.func = 'login';
    param.username = getAjaxValue('username');
    param.password = getAjaxValue('password');

    sendAjax(param, function(result) {
        setStorage('user_token', result.token);
        delStorage('duty_token');
        toUrl('admin.php?m=account&c=main');
    });
}